package com.kygeng.springframework.aop.framework;

import com.kygeng.springframework.aop.AdvisedSupport;

/**
 * @Title: ProxyFactory
 * @Author: kygeng
 * @Package: com.kygeng.springframework.aop.framework
 * @Date: 2024/8/11 11:22
 * @Description: 代理工厂:关于 JDK 和 Cglib 两种代理的选择问题，有了代理工厂就可以按照不同的创建需求进行控制。
 */
public class ProxyFactory {

    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy() {
        return createAopProxy().getProxy();
    }


    public AopProxy createAopProxy() {
        if (advisedSupport.isProxyTargetClass()) {
            return new Cglib2AopProxy(advisedSupport);
        } else {
            return new JdkDynamicAopProxy(advisedSupport);
        }
    }
}
